package com.monkeyboy.spring.component;

import com.monkeyboy.spring.service.A;
import com.monkeyboy.spring.service.UserService;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @Author Gavin
 * @date 2020.06.22 11:40
 */
//@Component
public class myBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		System.out.println("--------------------");
		GenericBeanDefinition a = (GenericBeanDefinition) beanFactory.getBeanDefinition("a");
		System.out.println(a.getBeanClass());
		a.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);//设置该bean的装配模式为自动构造装配
//		AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) beanFactory.getBeanDefinition("userService");
//		beanDefinition.getPropertyValues().setPropertyValueAt(new PropertyValue("key","value"),0);
	}
}
